#include <bits/stdc++.h>
using namespace std;

int n;
string front, centre, poster;
unordered_map<char, int> inorderMap;

void postorder(int preStart, int preEnd, int inStart, int inEnd){
    if(inStart >= inEnd || preStart >= preEnd){
        poster += centre[inEnd];
        return;
    }

    char root = front[preStart];
    int pos = inorderMap[root];
    int leftlen = pos - inStart;
    if(leftlen != 0) postorder(preStart + 1, preStart + leftlen, inStart, pos - 1);
    int rightlen = inEnd - pos;
    if(rightlen != 0) postorder(preEnd - rightlen + 1, preEnd, pos + 1, inEnd);
    poster += root;

}

int main(){
    
    while(cin >> n){
        inorderMap.clear();
        poster = "";
        if(n == 0) break;
        cin >> front >> centre;
        for(int i = 0; i < n; ++i){
            char ch = centre[i];
            inorderMap[ch] = i;
        }
        postorder(0, n - 1, 0, n - 1);
        
        cout << poster << endl;
    }
}